//
//  WelcomViewController.m
//  ZiJinLian
//
//  Created by 🐛 on 2017/7/5.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "WelcomViewController.h"
#import "AppDelegate.h"
#import "WebViewProgressLine.h"
#import "ShopDetailViewController.h"
#import "ApplyViewController.h"
@interface WelcomViewController ()<UIApplicationDelegate,UIWebViewDelegate>
//@property (strong, nonatomic) MianTabBarViewController *tabVC;
@property (nonatomic ,strong) UIImageView *welcomImg;
@property (nonatomic,strong) WebViewProgressLine  *progressLine;


@end

@implementation WelcomViewController

- (void)viewDidLoad {
    [super viewDidLoad];
	
    UIWebView *web = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, MainW, MainH-64)];
    NSURL *url = [NSURL URLWithString:_reLastURL];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [web loadRequest:request];
    [web sizeToFit];
	web.delegate = self;
    [self.view addSubview:web];
	
	self.progressLine = [[WebViewProgressLine alloc] initWithFrame:CGRectMake(0, 0, MainW, 2)];
	self.progressLine.lineColor = RGBA(61, 165, 256, 1);
	[self.view addSubview:self.progressLine];

    
    // 禁止回弹
    web.scrollView.bounces = NO;
    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,[[UIScreen mainScreen] bounds].size.width ,0)];
    topView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:topView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (BOOL)prefersStatusBarHidden{
    return NO;
}
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}
-(void)webViewDidStartLoad:(UIWebView *)webView{
	[self.progressLine startLoadingAnimation];
}

-(void)webViewDidFinishLoad:(UIWebView *)webView{
	[self.progressLine endLoadingAnimation];
	
	NSString *htmlTitle = @"document.title";
	NSString *numHtmlInfo = [webView stringByEvaluatingJavaScriptFromString:htmlTitle];
	self.title = numHtmlInfo;


}

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
	[self.progressLine endLoadingAnimation];
}
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
	
	NSString *urlstr = [request.URL absoluteString];
	NSLog(@"%@",urlstr);
	if ([urlstr containsString:@"sku/detail"]) {
		NSLog(@"11");
		NSRange range = [urlstr rangeOfString:@"="];
		if (range.location != NSNotFound) {
			NSString *skuid = [urlstr substringFromIndex:(range.location+1)];
			NSLog(@"skuid = %@",skuid);
			ShopDetailViewController *vc=[[ShopDetailViewController alloc]init];
			vc.spuId=skuid;
			[self.navigationController pushViewController:vc animated:YES];
			return NO;
		}
	}else if ([urlstr containsString:@"apply"]){
		
		NSLog(@"跳转经销商资料填写");
		ApplyViewController*vc=[[ApplyViewController alloc]init];
		vc.title=MyString(@"经销商申请");
		[self.navigationController pushViewController:vc animated:YES];

		return NO;
		
	}
	
	return YES;
	
}


@end
